require("../../requests/request.js");

var o = getApp();

Page({
    data: {
        userid: "nodata",
        username: "",
        userpic: "",
        islogin: !1
    },
    onLoad: function(o) {
        this.setData({
            userid: "test01",
            username: "test01"
        });
    },
    sendMsg: function(o) {
        console.log(o);
    },
    checkIsLogin: function(o) {
        wx.checkSession({
            success: function() {
                console.log("session 未过期，并且在本生命周期一直有效");
            },
            fail: function() {
                console.log("登录态过期");
            }
        });
    },
    onLaunch: function() {
        console.log("onLaunch");
        var s = this;
        wx.login({
            success: function(e) {
                console.log(e), e.code ? wx.request({
                    url: "https://wxs.app.yiche.com/wxlogin.ashx",
                    data: {
                        code: e.code
                    },
                    success: function(e) {
                        console.log(e.data);
                        var n = e.data;
                        o.openid = n.openid, console.log(n.openid), s.setData({
                            userid: n.openid
                        });
                    },
                    fail: function(o) {
                        console.log(o);
                    }
                }) : console.log("获取用户登录态失败！" + e.errMsg);
            }
        });
    }
});